package com.ybg.dao;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.ybg.bean.SystemConfig;
import com.ybg.utils.YbgException;

/**
 * 系统参数DAO类
 * 
 * @author ningjh
 * @since  2016-08-12
 */
@Repository
public class SystemConfigDao extends AbstractDao {
	private static RowMapper<SystemConfig> rowMapper = new YbgRowMapper<SystemConfig>(SystemConfig.class);
	
	/**
	 * 查询所有系统配置
	 * 
	 * @return
	 */
	public List<SystemConfig> queryForList() {
		String sql = "select * from system_config";
		return jdbcTemplate.query(sql, rowMapper);
	}
	
	/**
	 * 查询单个系统配置
	 * 
	 * @param key
	 * @return
	 */
	public String querySingle(String key) {
		String sql = "select paramvalue from system_config where paramkey=?";
		
		try {
			return jdbcTemplate.queryForObject(sql, String.class, key);
		} catch (DataAccessException e) {
			throw new YbgException("0009", e);
		}
	}
}
